﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZX.HIS.IDAL;
using ZX.HIS.DBUtility;
using ZX.HIS.Common;
using System.Collections.Generic;//Please add references
namespace ZX.HIS.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:AuthorInfo
	/// </summary>
	public partial class AuthorInfo:IAuthorInfo
	{
		public AuthorInfo()
		{ }
        #region 自写方法
        /// <summary>
        /// 权限表分页显示
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public PageClass<ZX.HIS.Model.AuthorInfo> allAuthorInfo(int PageIndex, int PageSize)
        {
            string Comtext = "dbo.Proc_AuthorInfo";
            SqlParameter[] parameters ={
                           new SqlParameter("@PageIndex",SqlDbType.Int){Value=PageIndex},
                           new SqlParameter("@PageSize",SqlDbType.Int){Value=PageSize}
                                      };

            List<ZX.HIS.Model.AuthorInfo> List = new List<ZX.HIS.Model.AuthorInfo>();

            //调用SqlDBhelper

            int PageNum = 0;
            DataTable dt = SqlDBhelper.RunProcedure(Comtext, parameters, PageSize,  PageIndex, out  PageNum);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ZX.HIS.Model.AuthorInfo model = new ZX.HIS.Model.AuthorInfo();

                model.AuthorId = Convert.ToInt32(dt.Rows[i]["AuthorId"]);
                model.AuthorName = dt.Rows[i]["AuthorName"].ToString();
                model.AuthorParentId = Convert.ToInt32(dt.Rows[i]["AuthorParentId"]);
                model.AuthorState = Convert.ToInt32(dt.Rows[i]["AuthorState"]);
                model.AuthorUrl = dt.Rows[i]["AuthorUrl"].ToString();
                model.HospitalId = Convert.ToInt32(dt.Rows[i]["HospitalId"]);
                List.Add(model);
            }
            //实例化pager类
            PageClass<ZX.HIS.Model.AuthorInfo> Page = new PageClass<ZX.HIS.Model.AuthorInfo>();
            Page.PageIndex = PageIndex;
            Page.PageSize = PageSize;
            Page.PageNum = PageNum;
            Page.PageCount = PageNum / PageSize;
            int PageCount = PageNum % PageSize;
            Page.PageList = List;
            if (PageCount > 0)
            {
                Page.PageCount = Page.PageCount + 1;
            }
            return Page;
        }

        /// <summary>
        /// 获得一个 权限表实体类
        /// </summary>
        /// <param name="PatientId"></param>
        /// <returns></returns>
        public ZX.HIS.Model.AuthorInfo GetAuthorInfoModel(int AuthorId)
        {
        string Comtext = "dbo.Proc_AuthorInfoModel";
        SqlParameter[] parameters ={
                           new SqlParameter("@AuthorId",SqlDbType.Int){Value=AuthorId}
                                      };

        DataSet ds = SqlDBhelper.RunProcedure(Comtext, parameters, "db");

        if (ds.Tables[0].Rows.Count > 0)
        {
            return DataRowToModel(ds.Tables[0].Rows[0]);
        }
        else
        {
            return null;
        }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZX.HIS.Model.AuthorInfo DataRowToModel(DataRow row)
        {
            ZX.HIS.Model.AuthorInfo model = new Model.AuthorInfo();

            if (row != null)
            {
                if (row["AuthorId"] != null && row["AuthorId"].ToString() != "")
                {
                    model.AuthorId = int.Parse(row["AuthorId"].ToString());
                }

                if (row["AuthorName"] != null)
                {
                    model.AuthorName = row["AuthorName"].ToString();
                }

                if (row["AuthorUrl"] != null)
                {
                    model.AuthorUrl = row["AuthorUrl"].ToString();
                }

             
                if (row["AuthorParentId"] != null && row["AuthorParentId"].ToString() != "")
                {
                    model.AuthorParentId = int.Parse(row["AuthorParentId"].ToString());
                }
              
            }
            return model;
        }
          
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="AuthorId"></param>
        /// <param name="AuthorState"></param>
        /// <returns></returns>
        public bool delAuthorInfo(int AuthorId, int AuthorState)
        {
            string Comtext = "dbo.Proc_AuthorInfoupt";
            SqlParameter[] parameters ={
                           new SqlParameter("@AuthorId",SqlDbType.Int){Value=AuthorId},
                           new SqlParameter("@AuthorState",SqlDbType.Int){Value=AuthorState}
                                      };
            return SqlDBhelper.RunProcedureNonQuery(Comtext, parameters);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="AuthorId"></param>
        /// <param name="AuthorName"></param>
        /// <param name="AuthorUrl"></param>
        /// <param name="AuthorParentId"></param>
        /// <returns></returns>
        public bool updAuthorInfo(int AuthorId,string AuthorName,string AuthorUrl,int AuthorParentId)
        {
            string Comtext = "dbo.Proc_AuthorInfouptDO";
            SqlParameter[] parameters ={
                           new SqlParameter("@AuthorId",SqlDbType.Int){Value=AuthorId},
                           new SqlParameter("@AuthorName",SqlDbType.VarChar){Value=AuthorName},
                            new SqlParameter("@AuthorUrl",SqlDbType.VarChar){Value=AuthorUrl},
                             new SqlParameter("@AuthorParentId",SqlDbType.Int){Value=AuthorParentId}
                                      };
            return SqlDBhelper.RunProcedureNonQuery(Comtext,parameters);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="HospitalId"></param>
        /// <param name="AuthorName"></param>
        /// <param name="AuthorUrl"></param>
        /// <param name="AuthorParentId"></param>
        /// <param name="AuthorState"></param>
        /// <returns></returns>
        public bool addAuthorInfo(int HospitalId,string AuthorName,string AuthorUrl,int AuthorParentId,int AuthorState)
        { 
             string Comtext = "dbo.Proc_AuthorInfoAdd";
            SqlParameter[] parameters ={
                           new SqlParameter("@HospitalId",SqlDbType.Int){Value=HospitalId},
                           new SqlParameter("@AuthorName",SqlDbType.VarChar){Value=AuthorName},
                            new SqlParameter("@AuthorUrl",SqlDbType.VarChar){Value=AuthorUrl},
                             new SqlParameter("@AuthorParentId",SqlDbType.Int){Value=AuthorParentId},
                              new SqlParameter("@AuthorState",SqlDbType.Int){Value=AuthorState}
                                      };
            return SqlDBhelper.RunProcedureNonQuery(Comtext, parameters);
        }

        #endregion

        #region  BasicMethod

        ///// <summary>
        ///// 得到最大ID
        ///// </summary>
        //public int GetMaxId()
        //{
        //return DbHelperSQL.GetMaxID("AuthorId", "tbAuthorInfo"); 
        //}

        ///// <summary>
        ///// 是否存在该记录
        ///// </summary>
        //public bool Exists(int AuthorId)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) from tbAuthorInfo");
        //    strSql.Append(" where AuthorId=@AuthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@AuthorId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = AuthorId;

        //    return DbHelperSQL.Exists(strSql.ToString(),parameters);
        //}


        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public int Add(ZX.HIS.Model.AuthorInfo model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("insert into tbAuthorInfo(");
        //    strSql.Append("HospitalId,AuthorName,AuthorUrl,AuthorParentId,AuthorState)");
        //    strSql.Append(" values (");
        //    strSql.Append("@HospitalId,@AuthorName,@AuthorUrl,@AuthorParentId,@AuthorState)");
        //    strSql.Append(";select @@IDENTITY");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@AuthorName", SqlDbType.VarChar,50),
        //            new SqlParameter("@AuthorUrl", SqlDbType.VarChar,100),
        //            new SqlParameter("@AuthorParentId", SqlDbType.Int,4),
        //            new SqlParameter("@AuthorState", SqlDbType.Int,4)};
        //    parameters[0].Value = model.HospitalId;
        //    parameters[1].Value = model.AuthorName;
        //    parameters[2].Value = model.AuthorUrl;
        //    parameters[3].Value = model.AuthorParentId;
        //    parameters[4].Value = model.AuthorState;

        //    object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(ZX.HIS.Model.AuthorInfo model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("update tbAuthorInfo set ");
        //    strSql.Append("HospitalId=@HospitalId,");
        //    strSql.Append("AuthorName=@AuthorName,");
        //    strSql.Append("AuthorUrl=@AuthorUrl,");
        //    strSql.Append("AuthorParentId=@AuthorParentId,");
        //    strSql.Append("AuthorState=@AuthorState");
        //    strSql.Append(" where AuthorId=@AuthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@AuthorName", SqlDbType.VarChar,50),
        //            new SqlParameter("@AuthorUrl", SqlDbType.VarChar,100),
        //            new SqlParameter("@AuthorParentId", SqlDbType.Int,4),
        //            new SqlParameter("@AuthorState", SqlDbType.Int,4),
        //            new SqlParameter("@AuthorId", SqlDbType.Int,4)};
        //    parameters[0].Value = model.HospitalId;
        //    parameters[1].Value = model.AuthorName;
        //    parameters[2].Value = model.AuthorUrl;
        //    parameters[3].Value = model.AuthorParentId;
        //    parameters[4].Value = model.AuthorState;
        //    parameters[5].Value = model.AuthorId;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// 删除一条数据
        ///// </summary>
        //public bool Delete(int AuthorId)
        //{
			
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from tbAuthorInfo ");
        //    strSql.Append(" where AuthorId=@AuthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@AuthorId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = AuthorId;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        ///// <summary>
        ///// 批量删除数据
        ///// </summary>
        //public bool DeleteList(string AuthorIdlist )
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from tbAuthorInfo ");
        //    strSql.Append(" where AuthorId in ("+AuthorIdlist + ")  ");
        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.AuthorInfo GetModel(int AuthorId)
        //{
			
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select  top 1 AuthorId,HospitalId,AuthorName,AuthorUrl,AuthorParentId,AuthorState from tbAuthorInfo ");
        //    strSql.Append(" where AuthorId=@AuthorId");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@AuthorId", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = AuthorId;

        //    ZX.HIS.Model.AuthorInfo model=new ZX.HIS.Model.AuthorInfo();
        //    DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
        //    if(ds.Tables[0].Rows.Count>0)
        //    {
        //        return DataRowToModel(ds.Tables[0].Rows[0]);
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.AuthorInfo DataRowToModel(DataRow row)
        //{
        //    ZX.HIS.Model.AuthorInfo model=new ZX.HIS.Model.AuthorInfo();
        //    if (row != null)
        //    {
        //        if(row["AuthorId"]!=null && row["AuthorId"].ToString()!="")
        //        {
        //            model.AuthorId=int.Parse(row["AuthorId"].ToString());
        //        }
        //        if(row["HospitalId"]!=null && row["HospitalId"].ToString()!="")
        //        {
        //            model.HospitalId=int.Parse(row["HospitalId"].ToString());
        //        }
        //        if(row["AuthorName"]!=null)
        //        {
        //            model.AuthorName=row["AuthorName"].ToString();
        //        }
        //        if(row["AuthorUrl"]!=null)
        //        {
        //            model.AuthorUrl=row["AuthorUrl"].ToString();
        //        }
        //        if(row["AuthorParentId"]!=null && row["AuthorParentId"].ToString()!="")
        //        {
        //            model.AuthorParentId=int.Parse(row["AuthorParentId"].ToString());
        //        }
        //        if(row["AuthorState"]!=null && row["AuthorState"].ToString()!="")
        //        {
        //            model.AuthorState=int.Parse(row["AuthorState"].ToString());
        //        }
        //    }
        //    return model;
        //}

        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public DataSet GetList(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select AuthorId,HospitalId,AuthorName,AuthorUrl,AuthorParentId,AuthorState ");
        //    strSql.Append(" FROM tbAuthorInfo ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top,string strWhere,string filedOrder)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select ");
        //    if(Top>0)
        //    {
        //        strSql.Append(" top "+Top.ToString());
        //    }
        //    strSql.Append(" AuthorId,HospitalId,AuthorName,AuthorUrl,AuthorParentId,AuthorState ");
        //    strSql.Append(" FROM tbAuthorInfo ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    strSql.Append(" order by " + filedOrder);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获取记录总数
        ///// </summary>
        //public int GetRecordCount(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) FROM tbAuthorInfo ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    object obj = DbHelperSQL.GetSingle(strSql.ToString());
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("SELECT * FROM ( ");
        //    strSql.Append(" SELECT ROW_NUMBER() OVER (");
        //    if (!string.IsNullOrEmpty(orderby.Trim()))
        //    {
        //        strSql.Append("order by T." + orderby );
        //    }
        //    else
        //    {
        //        strSql.Append("order by T.AuthorId desc");
        //    }
        //    strSql.Append(")AS Row, T.*  from tbAuthorInfo T ");
        //    if (!string.IsNullOrEmpty(strWhere.Trim()))
        //    {
        //        strSql.Append(" WHERE " + strWhere);
        //    }
        //    strSql.Append(" ) TT");
        //    strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///*
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@tblName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@fldName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PageSize", SqlDbType.Int),
        //            new SqlParameter("@PageIndex", SqlDbType.Int),
        //            new SqlParameter("@IsReCount", SqlDbType.Bit),
        //            new SqlParameter("@OrderType", SqlDbType.Bit),
        //            new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
        //            };
        //    parameters[0].Value = "tbAuthorInfo";
        //    parameters[1].Value = "AuthorId";
        //    parameters[2].Value = PageSize;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = 0;
        //    parameters[5].Value = 0;
        //    parameters[6].Value = strWhere;	
        //    return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        //}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

